// useEffect
import { useEffect } from "react"
import { useState } from "react"

function Son () {
  // 渲染时开启一个定时器
  useEffect(()=>{
    const timer = setInterval(()=>{
      console.log('定时器执行中')
    }, 1000)
    return () => {
      // 清除副作用(组件卸载)
      clearInterval(timer)
    }
  },[])
  return <div>this is son</div>
}


function App() {
  //通过条件模拟组件卸载
  const [show,setShow] = useState(true)
  return (
    <div>
     this is app
      <button onClick={() => setShow(false)}>卸载son组件</button>
      {show && <Son/>}
    </div>
  )
}   

export default App
